package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybaitisConfig {
    @Bean
    //获取工厂
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setTypeAliasesPackage("com.itheima.pojo");
        bean.setDataSource(dataSource);
        return bean;
    }

    //获取映射
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mscf = new MapperScannerConfigurer();
        mscf.setBasePackage("com.itheima.mapper");
        return mscf;
    }
}
